#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import sys
import cv2

# 从命令行获取图像文件路径
if len(sys.argv) < 2:
    print("请提供图像文件路径作为命令行参数")
    sys.exit(1)

image_path = sys.argv[1]

img = cv2.imread(image_path)
if img is None:
    print("无法读取图像文件")
    sys.exit(1)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

def mouse_click(event, x, y, flags, para):
    if event == cv2.EVENT_LBUTTONDOWN:  # 左边鼠标点击
        #print('PIX:', x, y)
        #print("BGR:", img[y, x])
        #print("GRAY:", gray[y, x])
        print("HSV:", hsv[y, x])

if __name__ == '__main__':
    cv2.namedWindow("img")
    cv2.setMouseCallback("img", mouse_click)
    while True:
        cv2.imshow('img', img)
        if cv2.waitKey() == ord('q'):
            break
    cv2.destroyAllWindows()